<template>
  <view class="user_Overview flex">
    <view class="user_Overview-item" style="color: #00fdfa">
      <view class="user_Overview_nums allnum">
        <CountUp :endVal="state.totalNum" :duration="duration" />
      </view>
      <text>总设备数</text>
    </view>
    <view class="user_Overview-item" style="color: #07f7a8">
      <view class="user_Overview_nums online">
        <CountUp :endVal="state.onlineNum" :duration="duration" />
      </view>
      <text>在线数</text>
    </view>
    <view class="user_Overview-item" style="color: #e3b337">
      <view class="user_Overview_nums offline">
        <CountUp :endVal="state.offlineNum" :duration="duration" />
      </view>
      <text>掉线数</text>
    </view>
    <view class="user_Overview-item" style="color: #f5023d">
      <view class="user_Overview_nums laramnum">
        <CountUp :endVal="state.alarmNum" :duration="duration" />
      </view>
      <text>告警次数</text>
    </view>
  </view>
</template>

<script setup>
import { reactive, ref, onMounted } from 'vue'
import CountUp from '@/components/count-up/count-up.vue'

const duration = ref(2)
const state = reactive({
  alarmNum: 0,
  offlineNum: 0,
  onlineNum: 0,
  totalNum: 0
})

const getData = () => {
  // 使用固定模拟数据
  state.alarmNum = 567
  state.offlineNum = 35
  state.onlineNum = 663
  state.totalNum = 698
}

onMounted(() => {
  getData()
})
</script>

<style scoped lang="scss">
.user_Overview {
  display: flex;
  width: 100%;

  .user_Overview-item {
    flex: 1;
    text-align: center;

    text {
      display: block;
      text-align: center;
      height: 16px;
      font-size: 16px;
    }

    .user_Overview_nums {
      width: 100px;
      height: 100px;
      text-align: center;
      line-height: 100px;
      font-size: 22px;
      margin: 50px auto 30px;
      background-size: cover;
      background-position: center center;
      position: relative;

      &::before {
        content: '';
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
      }

      &.bgdonghua::before {
        animation: rotating 14s linear infinite;
      }
    }

    .allnum {
      &::before {
        background-image: url('/static/img/left_top_lan.png');
      }
    }

    .online {
      &::before {
        background-image: url('/static/img/left_top_lv.png');
      }
    }

    .offline {
      &::before {
        background-image: url('/static/img/left_top_huang.png');
      }
    }

    .laramnum {
      &::before {
        background-image: url('/static/img/left_top_hong.png');
      }
    }
  }
}

@keyframes rotating {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
</style>

